package com.shanzmoo.core.config.pay;

import com.shanzmoo.core.pay.sdk.wxpay.IWXPayDomain;
import com.shanzmoo.core.pay.sdk.wxpay.WXPayConfig;
import com.shanzmoo.core.pay.sdk.wxpay.WXPayConstants;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class MyWxPayConfig extends WXPayConfig {

    private byte[] certData;

    public MyWxPayConfig(){
        // 暂无退款需求，不配置证书
//        String certPath = "/path/to/apiclient_cert.p12";
//        File file = new File(certPath);
//        InputStream certStream = new FileInputStream(file);
//        this.certData = new byte[(int) file.length()];
//        certStream.read(this.certData);
//        certStream.close();
    }

    @Override
    public String getAppID() {
        return "wxe1eb5006742003bc";
    }

    @Override
    public String getMchID() {
        return "1604272417";
    }

    /**
     *  appkey， 商户 api 秘钥，
     * @return
     */
    @Override
    public String getKey() {
        return "sSBQXaW2cquey6dzCXa01d2HYLYZdebN";
    }

    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        IWXPayDomain iwxPayDomain = new IWXPayDomain() {

            public void report(String domain, long elapsedTimeMillis, Exception ex) {
            }

            public DomainInfo getDomain(WXPayConfig config) {
                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
    }
}
